package org.cloud.im.core.listener;

import org.cloud.im.core.ImChannelContext;
import org.cloud.im.core.ImConst;
import org.cloud.im.core.packets.Group;
import org.tio.core.ChannelContext;
import org.tio.core.intf.GroupListener;

/**
 * @Author: w.weidong.lin@abite.com
 * @Description: TODO
 * @Date: create in 2021/10/19 15:01
 */
public class ImGroupListenerAdapter implements GroupListener, ImConst {

    private ImGroupListener imGroupListener;

    public ImGroupListenerAdapter(ImGroupListener imGroupListener) {
        this.imGroupListener = imGroupListener;
    }

    @Override
    public void onAfterBind(ChannelContext channelContext, String group) throws Exception {
        ImChannelContext imChannelContext = (ImChannelContext) channelContext.get(Key.IM_CHANNEL_CONTEXT_KEY);
        imGroupListener.onAfterBind(imChannelContext, Group.newBuilder().groupId(group).build());
    }

    @Override
    public void onAfterUnbind(ChannelContext channelContext, String group) throws Exception {
        ImChannelContext imChannelContext = (ImChannelContext) channelContext.get(Key.IM_CHANNEL_CONTEXT_KEY);
        imGroupListener.onAfterUnbind(imChannelContext, Group.newBuilder().groupId(group).build());
    }
}
